<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <span id="show"></span>
    <script>
        // 把当前的时间显示输出在页面
        function timer(){
            var date = new Date()
            var years = date.getFullYear()
            var month = date.getMonth() + 1
            var days = date.getDate()
            var hours = date.getHours()
            var min = date.getMinutes()
            var sec = date.getSeconds()
            hours =  hours < 10 ? '0' + hours : hours
            min =  min < 10 ? '0' + min : min
            sec =  sec < 10 ? '0' + sec : sec
            
            return ' '+ years + '/' + month + '/' + days + ' ' + hours + ':' + min + ':' + sec
        }
        
        setInterval(function(){
            show.innerHTML = '当前时间为：' + timer()
        },1000)
    </script>
</body>
</html>